
import * as THREE from "three"
import rain from "../assets/img/rain.png"
import { MyPoints } from "../utils/Points"
export class Rain {
    scene: THREE.Scene
    config: myPoints
    snow
    constructor(scene: THREE.Scene) {
        this.scene = scene
        let range = 500
        this.config = {
            scene,
            count: 300,
            opacity: 0.8,
            size: 20,
            range,
            textureUrl: rain,
            // 设置xyz方向速度
            setSpeed: function (vect: myVector) {
                vect.speedx = Math.random() * 0.1 - 0.05
                vect.speedy = - Math.random() * 0.8 - 0.1
                vect.speedz = Math.random() *  0.1 - 0.05

            },
            // 设置初始位置
            setPosition: function (vect: myVector) {
                vect.x = THREE.MathUtils.randFloatSpread(range * 2)
                vect.y = THREE.MathUtils.randFloat(0, range)
                vect.z = THREE.MathUtils.randFloatSpread(range * 2)

            },
            // 设置帧动画处理逻辑
            setAnimation: function (vect: myVector) {
                vect.x += vect.speedx
                vect.y += vect.speedy
                vect.z += vect.speedz
                if (vect.y <= 0) {
                    this.setPosition(vect)
                }
            }
        }
        this.snow = new MyPoints(this.config)
    }
    animation() {
        this.snow.animation()
    }
}